<template>
  <el-container style="height: 100%">
    <el-header style="position: fixed;z-index: 9;width: 100%">
      <h1 class="title">
                        <span style="color: #5f5b5b">
                            当前位置 ：
                        </span>
        建筑数据调查
      </h1>
    </el-header>
    <el-main style="background: #F0F0F066;margin-top:45px">
      <el-row>
        <el-col :span="24">
          <el-row :gutter="10">
            <el-card>
              <el-row>
                <!--                                <h1 style="font-size: 1.4em"> 任务列表</h1>-->
                <h1 style="font-size: 1.4em">
                  <el-input v-model="taskName" placeholder="请输入任务名" clearable size="medium" style="width: 200px"
                            @input="findByTaskName"></el-input>
                </h1>
                <br>
                <el-button class="el-button--primary" @click="to('BuildingNewMission')"
                           style="margin-left: -4px">发布新任务
                </el-button>
              </el-row>
              <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="全部任务" name="first">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
                <el-tab-pane label="未领取任务" name="second">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
                <el-tab-pane label="已认领任务" name="third">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
                <el-tab-pane label="数据有上传" name="fourth">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
                <el-tab-pane label="等待质检" name="fifth">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
                <el-tab-pane label="质检不合格" name="sixth">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
                <el-tab-pane label="质检合格" name="seventh">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
                <el-tab-pane label="数据入库" name="eighth">
                  <task-table :table-data="tableData" :path="path" :history-path="historyPath"
                              :cur-page="curPage"
                              @updateData="updateData"/>
                </el-tab-pane>
              </el-tabs>
            </el-card>
            <admin-page :page-size="pageSize" ref="adminPage" @updateData="updateData"
                        :total="total" @currentChange="currentChange"/>
          </el-row>
        </el-col>
      </el-row>
    </el-main>
  </el-container>
</template>

<script>
import TaskTable from "../../../../components/admin/table/building/BTaskTable";
import AdminPage from "../../../../components/admin/menu/AdminPage";
import qs from "qs";

export default {
  name: "Tl",
  components: {
    TaskTable,
    AdminPage
  },
  data() {
    return {
      activeName: 'first',
      tableData: [],
      beginPos: '',
      curPage: 1,
      pageSize: 10,
      total: 0,
      state: 0,
      type: 1,
      path: 'BuildingNode',
      historyPath: 'BuildingHistory',
      taskName: ''
    }
  },
  mounted() {
    this.updateData(this.curPage, this.state, this.input);
  },
  methods: {
    handleClick(tab) {
      let state = tab.index == 0 ?
          0 : tab.index == 1 ?
              1 : tab.index == 2 ?
                  2 : tab.index == 3 ?
                      3 : tab.index == 4 ?
                          4 : tab.index == 5 ?
                              5 : tab.index == 6 ?
                                  6 : 7;
      this.updateData(1, state, this.taskName);
    },
    to(path) {
      this.$router.push({name: path});
    },
    currentChange(curPage) {
      this.updateData(curPage, this.state, this.taskName);
    },
    findByTaskName(taskName) {
      this.updateData(this.curPage, this.state, taskName);
    },
    updateData(curPage, state, taskName) {
      this.pageSize = this.$refs.adminPage.pageSize;
      this.curPage = curPage === undefined ? this.curPage : curPage;
      this.state = state === undefined ? this.state : state;
      this.taskName = taskName === undefined ? this.taskName : taskName;
      axios.get("/bjdzms/releaseTask/findAllByType",
          {
            params: {
              'page': this.curPage,
              'rows': this.pageSize,
              'type': this.type,
              'state': this.state,
              'taskName': this.taskName
            }
          }).then(res => {
        this.tableData = [];
        this.tableData = res.data.rows;
        this.beginPos = res.data.beginPos;
        this.curPage = res.data.curPage;
        this.pageCount = res.data.pageCount;
        this.total = res.data.total;
      });
    }
  }
}
</script>

<style scoped>
.el-header {
  background: #EBEBEB;
  color: #e5e9ef;
  font-size: 2em;
  line-height: 80px;
  border: 5px solid #EBEBEB;
}

.title {
  font-size: 14px;
  color: #97a8be;
  font-weight: 400 !important;
}

.el-main {
  background: #fff;
}

.el-container {
  height: 100%;
}

.title {
  font-size: 14px;
  color: #97a8be;
  font-weight: 400 !important;
}
</style>
